package vng.wcc.sonph.Demo;

import vng.wcc.sonph.LauncherGenerator.CellInfo;
import vng.wcc.sonph.LauncherGenerator.Formatter;
import vng.wcc.sonph.LauncherGenerator.LauncherWithTabsGenerator;
import vng.wcc.sonph.LauncherGenerator.R;
import vng.wcc.sonph.LauncherGenerator.TabCellInfo;
import vng.wcc.sonph.LauncherGenerator.TabFormatter;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;

public class LauncherWithTabDemo extends LauncherWithTabsGenerator {

	private static final int NUM_COLS_PER_PAGE = 3;
	private Intent[] intent;
	private CellInfo[][] items;
	private TabCellInfo[] tabinfo;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		//TODONE: remove this code and WRITE_EXTERNAL_STORAGE permission
//		Debug.startMethodTracing("LGen");
		setDemoData();
		try {
			createLauncherWithTabView(items, tabinfo, NUM_COLS_PER_PAGE);
			setContentView(this.getRootView());
		} catch (Exception e) {
			Log.w("Error: ",e.getMessage());
		}

	}
	@Override
	public void onStop() {
		super.onStop();
//		Debug.stopMethodTracing();
	}

	private void setDemoData() {
		//Create intent to launch by clicking on the icon
		intent = new Intent[2];
		intent[0] = new Intent(this,vng.wcc.sonph.Demo.ShowOddMessage.class);
		intent[1] = new Intent(this,vng.wcc.sonph.Demo.ShowEvenMessage.class);

		//Create the items to add into the view
		items = new CellInfo[3][];		

		//Provide the layout for the LauncherView
		Formatter cellFormatter = new Formatter(this, NUM_COLS_PER_PAGE);

		items[0] = new CellInfo[9];
		items[0][0] = new CellInfo(this,R.drawable.home,cellFormatter, "Trang chu Zing", intent[0]);
		items[0][1] = new CellInfo(this,R.drawable.blog,cellFormatter, "Zing me", intent[0]);
		items[0][2] = new CellInfo(this,R.drawable.chat,cellFormatter,"Zing Chat", intent[1]);
		items[0][3] = new CellInfo(this,R.drawable.news,cellFormatter,"Zing News", intent[0]);		
		items[0][4] = new CellInfo(this,R.drawable.mail,cellFormatter,"Zing Mail!", createSendMailIntent());
		items[0][5] = new CellInfo(this,R.drawable.mp3player,cellFormatter, "Zing Mp3", createPlayMusicIntent());
		items[0][6] = new CellInfo(this,R.drawable.home,cellFormatter, "Trang chu Zing", intent[0]);
		items[0][7] = new CellInfo(this,R.drawable.home,cellFormatter, "Trang chu Zing", intent[0]);
		items[0][8] = new CellInfo(this,R.drawable.home,cellFormatter, "Trang chu Zing", intent[0]);

		items[1] = new CellInfo[3];
		items[1][0] = new CellInfo(this,R.drawable.money, cellFormatter,"Chuyen doi tien", intent[0]);
		items[1][1] = new CellInfo(this,R.drawable.shopping, cellFormatter,"123 Mua", intent[1]);
		items[1][2] = new CellInfo(this,R.drawable.cinema, cellFormatter,"Lich chieu phim", intent[0]);

		items[2] = new CellInfo[6];
		items[2][0] = new CellInfo(this,R.drawable.animals, cellFormatter,"Nong trai vui ve", intent[0]);
		items[2][1] = new CellInfo(this,R.drawable.castle, cellFormatter,"Lau dai ma", intent[0]);
		items[2][2] = new CellInfo(this,R.drawable.chess, cellFormatter,"Co vua", intent[0]);
		items[2][3] = new CellInfo(this,R.drawable.deathrace, cellFormatter,"Death race", intent[0]);
		items[2][4] = new CellInfo(this,R.drawable.dice, cellFormatter,"Xoc dia", intent[0]);
		items[2][5] = new CellInfo(this,R.drawable.king, cellFormatter,"Lam sep !", intent[0]);

		//		items[3] = new CellInfo[12];
		//		items[3][0] = new CellInfo(this,R.drawable.home,cellFormatter, "Trang chu Zing", intent[0]);
		//		items[3][1] = new CellInfo(this,R.drawable.blog,cellFormatter, "Zing me", intent[0]);
		//		items[3][2] = new CellInfo(this,R.drawable.chat,cellFormatter,"Zing Chat", intent[1]);
		//		items[3][3] = new CellInfo(this,R.drawable.news,cellFormatter,"Zing News", intent[0]);
		//		items[3][4] = new CellInfo(this,R.drawable.mail,cellFormatter,"Zing Mail!", intent[1]);		
		//		items[3][5] = new CellInfo(this,R.drawable.mp3player,cellFormatter, "Zing Mp3", intent[1]);
		//		items[3][6] = new CellInfo(this,R.drawable.animals, cellFormatter,"Nong trai vui ve", intent[0]);
		//		items[3][7] = new CellInfo(this,R.drawable.castle, cellFormatter,"Lau dai ma", intent[0]);
		//		items[3][8] = new CellInfo(this,R.drawable.chess, cellFormatter,"Co vua", intent[0]);
		//		items[3][9] = new CellInfo(this,R.drawable.deathrace, cellFormatter,"Death race", intent[0]);
		//		items[3][10] = new CellInfo(this,R.drawable.dice, cellFormatter,"Xoc dia", intent[0]);
		//		items[3][11] = new CellInfo(this,R.drawable.king, cellFormatter,"Lam sep !", intent[0]);

		//Tabs:
		tabinfo = new TabCellInfo[3];
		TabFormatter tabformatter = new TabFormatter(cellFormatter, tabinfo.length);
		tabinfo[0] = new TabCellInfo(this, R.drawable.main, R.drawable.main_act, tabformatter);
		tabinfo[1] = new TabCellInfo(this, R.drawable.information,R.drawable.information_act, tabformatter);
		tabinfo[2] = new TabCellInfo(this, R.drawable.gamepad,R.drawable.gamepad_act, tabformatter);
		//		tabinfo[3] = new TabCellInfo(this, R.drawable.information,R.drawable.information_act, tabformatter);
	}

	
	private Intent createPlayMusicIntent() {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		Uri u =	Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
		intent.setData(u);
		return intent;
	}

	private Intent createSendMailIntent() {
		final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
		emailIntent .setType("plain/text");
		emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"webmaster@website.com"});
		String mySubjext = "";
		emailIntent .putExtra(android.content.Intent.EXTRA_SUBJECT, mySubjext);
		String myBodyText = "";
		emailIntent .putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
		return Intent.createChooser(emailIntent, "Send mail...");		
	}

}
